Recieved without seeking

Original code- not taking proportions into account.

data04_cleaned <- data04 |>
  mutate(
    GeoArea_Type = case_when(
      GeoAreas_Local == 1 ~ "Local",
      GeoAreas_MultipleLocal == 1 ~ "Multiple Local",
      GeoAreas_RegionalWithin == 1 ~ "Regional Within",
      GeoAreas_State == 1 ~ "State",
      GeoAreas_RegionalAcross == 1 ~ "Regional Across",
      GeoAreas_MultipleState == 1 ~ "Multiple State",
      GeoAreas_National == 1 ~ "National",
      GeoAreas_International == 1 ~ "International",
      GeoAreas_Oth == 1 ~ "Other",
      TRUE ~ NA_character_
    )
  )

data_filtered <- data04_cleaned |>
  filter(FndRaise_LocGvtGrnt_Seek == 0 & FndRaise_LocGvtGrnt_Rcv == 1) 


contingency_table <- table(data_filtered$GeoArea_Type, data_filtered$FndRaise_LocGvtGrnt_Rcv)


print(contingency_table)
##                  
##                    1
##   International    4
##   Local           41
##   Multiple Local  17
##   Multiple State   1
##   National         4
##   Other            1
##   Regional Across  3
##   Regional Within 11
##   State            2
chi_squared_result <- chisq.test(contingency_table)


print(chi_squared_result)
## 
##  Chi-squared test for given probabilities
## 
## data:  contingency_table
## X-squared = 145.07, df = 8, p-value < 2.2e-16

Where I’m running into problems.

I am trying to test if the proportion of nonprofits receiving funding without seeking it is truly different between nonprofits focused on different areas, rather than just being influenced by sample size- but I cant for the life of me figure it out. Am I thinking about this wrong? When analyzing the contingency table it’s still using the counts.

data04_cleaned <- data04_cleaned |>
  mutate(
    GeoArea_Type = case_when(
      GeoAreas_Local == 1 ~ "Local",
      GeoAreas_MultipleLocal == 1 ~ "Multiple Local",
      GeoAreas_RegionalWithin == 1 ~ "Regional Within",
      GeoAreas_State == 1 ~ "State",
      GeoAreas_RegionalAcross == 1 ~ "Regional Across",
      GeoAreas_MultipleState == 1 ~ "Multiple State",
      GeoAreas_National == 1 ~ "National",
      GeoAreas_International == 1 ~ "International",
      GeoAreas_Oth == 1 ~ "Other",
      TRUE ~ NA_character_
    )
  )


total_per_geo <- data04_cleaned |>
  group_by(GeoArea_Type) |>
  summarise(total_in_geo_area = n())


data_filtered <- data04_cleaned |>
  filter(FndRaise_LocGvtGrnt_Seek == 0 & FndRaise_LocGvtGrnt_Rcv == 1)


proportions_by_geo <- data_filtered |>
  group_by(GeoArea_Type) |>
  summarise(
    received_not_seeking = n()  
  ) |>
  left_join(total_per_geo, by = "GeoArea_Type") |>
  mutate(proportion = received_not_seeking / total_in_geo_area) 

print(proportions_by_geo)
## # A tibble: 10 × 4
##    GeoArea_Type    received_not_seeking total_in_geo_area proportion
##    <chr>                          <int>             <int>      <dbl>
##  1 International                      4               176    0.0227 
##  2 Local                             41              2155    0.0190 
##  3 Multiple Local                    17               579    0.0294 
##  4 Multiple State                     1                70    0.0143 
##  5 National                           4               161    0.0248 
##  6 Other                              1                32    0.0312 
##  7 Regional Across                    3               115    0.0261 
##  8 Regional Within                   11               445    0.0247 
##  9 State                              2               289    0.00692
## 10 <NA>                               1                34    0.0294
contingency_table <- table(data_filtered$GeoArea_Type)

print(contingency_table)
## 
##   International           Local  Multiple Local  Multiple State        National 
##               4              41              17               1               4 
##           Other Regional Across Regional Within           State 
##               1               3              11               2
chi_squared_result <- chisq.test(contingency_table)


print(chi_squared_result)
## 
##  Chi-squared test for given probabilities
## 
## data:  contingency_table
## X-squared = 145.07, df = 8, p-value < 2.2e-16

Likelihood of recieving a funding if you apply for it.

# Load your data
df <- read.csv("YEAR-04-DATA-PUF.csv")

# List of the base variable names (without _Seek or _Rcv)
funding_types <- c("FndRaise_LocGvtGrnt",
                   "FndRaise_StateGvtGrnt",
                   "FndRaise_FedGvtGrnt",
                   "FndRaise_LocGvtCntrct",
                   "FndRaise_StateGvtCntrct",
                   "FndRaise_FedGvtCntrct",
                   "FndRaise_PFGrnt",
                   "FndRaise_CFGrnt",
                   "FndRaise_DAF",
                   "FndRaise_Corp_Found_Grnt",
                   "FndRaise_UntdWy",
                   "FndRaise_CombFedCmpgn",
                   "FndRaise_OthrGvngPrgrm")

# Calculate success rate for each funding type
success_rates <- sapply(funding_types, function(base) {
  seek_var <- paste0(base, "_Seek")
  rcv_var <- paste0(base, "_Rcv")
  
  sought <- df[[seek_var]] == 1
  received_if_sought <- df[[rcv_var]][sought] == 1
  
  mean(received_if_sought, na.rm = TRUE)
})

# Convert to data frame for display
success_df <- data.frame(
  FundingType = funding_types,
  SuccessRate = round(success_rates, 3)
)

# View the results
print(success_df)
##                                       FundingType SuccessRate
## FndRaise_LocGvtGrnt           FndRaise_LocGvtGrnt       0.810
## FndRaise_StateGvtGrnt       FndRaise_StateGvtGrnt       0.794
## FndRaise_FedGvtGrnt           FndRaise_FedGvtGrnt       0.653
## FndRaise_LocGvtCntrct       FndRaise_LocGvtCntrct       0.782
## FndRaise_StateGvtCntrct   FndRaise_StateGvtCntrct       0.784
## FndRaise_FedGvtCntrct       FndRaise_FedGvtCntrct       0.620
## FndRaise_PFGrnt                   FndRaise_PFGrnt       0.865
## FndRaise_CFGrnt                   FndRaise_CFGrnt       0.798
## FndRaise_DAF                         FndRaise_DAF       0.859
## FndRaise_Corp_Found_Grnt FndRaise_Corp_Found_Grnt       0.850
## FndRaise_UntdWy                   FndRaise_UntdWy       0.799
## FndRaise_CombFedCmpgn       FndRaise_CombFedCmpgn       0.559
## FndRaise_OthrGvngPrgrm     FndRaise_OthrGvngPrgrm       0.691

sector

##recieving local goverment grant

This indicates that the probability of receiving a local government grant is not evenly distributed across sectors. Some nonprofit sectors were significantly more likely to receive funding after seeking it, while others experienced lower success rates.

For instance, nonprofits in the Arts, Health, and Environment & Animals sectors had notably higher success rates, with over 75–85% of seekers receiving funding. In contrast, sectors like Human Services had a comparatively lower success rate, despite representing the largest number of seekers in the dataset. While sector size was controlled for in the statistical test, the difference in proportions remains meaningful.

data04_cleaned <- data04 |>
  mutate(
    sector_group = case_when(
      ntee1 == "A" ~ "I. Arts, Culture, Humanities",
      ntee1 == "B" ~ "II. Education",
      ntee1 %in% c("C", "D") ~ "III. Environment & Animals",
      ntee1 %in% c("E", "F", "G", "H") ~ "IV. Health",
      ntee1 %in% c("I", "J", "K", "L", "M", "N", "O", "P") ~ "V. Human Services",
      ntee1 == "Q" ~ "VI. International",
      ntee1 %in% c("R", "S", "T", "U", "V", "W") ~ "VII. Public/Societal Benefit",
      ntee1 == "X" ~ "VIII. Religion Related",
      ntee1 == "Y" ~ "IX. Mutual/Membership Benefit",
      ntee1 == "Z" ~ "X. Unknown/Unclassified",
      TRUE ~ "Other"
    )
  )

# Filter to only those who sought a local government grant
data_sought <- data04_cleaned |>
  filter(FndRaise_LocGvtGrnt_Seek == 1)

# Create contingency table for receiving by sector
contingency_table <- table(data_sought$sector_group, data_sought$FndRaise_LocGvtGrnt_Rcv)

# Run chi-square test
chi_squared_result <- chisq.test(contingency_table)
## Warning in chisq.test(contingency_table): Chi-squared approximation may be
## incorrect
# Output
print(contingency_table)
##                               
##                                  0   1
##   I. Arts, Culture, Humanities  68 422
##   II. Education                 25  53
##   III. Environment & Animals    33 110
##   IV. Health                    22 102
##   V. Human Services            151 617
##   VI. International              5  10
##   VII. Public/Societal Benefit  31 121
##   VIII. Religion Related         2   2
print(chi_squared_result)
## 
##  Pearson's Chi-squared test
## 
## data:  contingency_table
## X-squared = 23.573, df = 7, p-value = 0.001354
library(dplyr)
library(ggplot2)

# Filter to organizations that sought local government grants
data_sought <- data04_cleaned |>
  filter(FndRaise_LocGvtGrnt_Seek == 1)

# Calculate success rates per sector
success_by_sector <- data_sought |>
  group_by(sector_group) |>
  summarise(
    total_sought = n(),
    total_received = sum(FndRaise_LocGvtGrnt_Rcv == 1, na.rm = TRUE),
    success_rate = round(100 * total_received / total_sought, 1)
  ) |>
  arrange(desc(success_rate))

# Plot
ggplot(success_by_sector, aes(x = reorder(sector_group, success_rate), y = success_rate)) +
  geom_col(fill = "steelblue") +
  geom_text(aes(label = paste0(success_rate, "%")), hjust = -0.1, size = 3.5) +
  coord_flip() +
  labs(
    title = "Success Rate of Receiving Local Government Grants (Among Seekers)",
    x = "Nonprofit Sector",
    y = "Success Rate (%)"
  ) +
  theme_minimal(base_size = 12) +
  ylim(0, 110)

local gov grants - Weighted

We conducted a Rao & Scott-adjusted chi-squared test to evaluate whether the success rate of receiving local government grants differed across nonprofit sectors, among those that sought such funding. Using the year4wt weight to account for differences in response rates by size, sector, and region, the test revealed a statistically significant association between sector and funding success (F = 2.78, df = 6.90, p = 0.0072). This suggests that some nonprofit sectors are more or less likely to receive local government grants after seeking them.

library(dplyr)
library(ggplot2)
library(survey)
## Warning: package 'survey' was built under R version 4.4.3
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
# Step 1: Add sector groupings
data04_cleaned <- data04 |>
  mutate(
    sector_group = case_when(
      ntee1 == "A" ~ "I. Arts, Culture, Humanities",
      ntee1 == "B" ~ "II. Education",
      ntee1 %in% c("C", "D") ~ "III. Environment & Animals",
      ntee1 %in% c("E", "F", "G", "H") ~ "IV. Health",
      ntee1 %in% c("I", "J", "K", "L", "M", "N", "O", "P") ~ "V. Human Services",
      ntee1 == "Q" ~ "VI. International",
      ntee1 %in% c("R", "S", "T", "U", "V", "W") ~ "VII. Public/Societal Benefit",
      ntee1 == "X" ~ "VIII. Religion Related",
      ntee1 == "Y" ~ "IX. Mutual/Membership Benefit",
      ntee1 == "Z" ~ "X. Unknown/Unclassified",
      TRUE ~ "Other"
    )
  )

# Step 2: Filter to those who sought local government grants
data_sought <- data04_cleaned |>
  filter(FndRaise_LocGvtGrnt_Seek == 1) |>
  mutate(
    FndRaise_LocGvtGrnt_Rcv = factor(FndRaise_LocGvtGrnt_Rcv, levels = c(0, 1)),
    sector_group = factor(sector_group)
  )

# Step 3: Set up weighted survey design
design <- svydesign(ids = ~1, weights = ~year4wt, data = data_sought)

# Step 4: Run weighted chi-square test
chi_result <- svychisq(~ sector_group + FndRaise_LocGvtGrnt_Rcv, design = design)

# Step 5: Print results
print(chi_result)
## 
##  Pearson's X^2: Rao & Scott adjustment
## 
## data:  svychisq(~sector_group + FndRaise_LocGvtGrnt_Rcv, design = design)
## F = 2.7811, ndf = 6.9013, ddf = 12235.9374, p-value = 0.007168
# Step 6: Plot success rates (still unweighted for visualization)
success_by_sector <- data_sought |>
  group_by(sector_group) |>
  summarise(
    total_sought = n(),
    total_received = sum(FndRaise_LocGvtGrnt_Rcv == 1, na.rm = TRUE),
    success_rate = round(100 * total_received / total_sought, 1)
  ) |>
  arrange(desc(success_rate))

ggplot(success_by_sector, aes(x = reorder(sector_group, success_rate), y = success_rate)) +
  geom_col(fill = "steelblue") +
  geom_text(aes(label = paste0(success_rate, "%")), hjust = -0.1, size = 3.5) +
  coord_flip() +
  labs(
    title = "Success Rate of Receiving Local Government Grants (Among Seekers)",
    x = "Nonprofit Sector",
    y = "Success Rate (%)"
  ) +
  theme_minimal(base_size = 12) +
  ylim(0, 110)

seeking and recieving state gov grant- Not weighted

To assess whether the likelihood of receiving a state government grant differs by nonprofit sector among those that sought funding, a chi-square test of independence was conducted. The test revealed a statistically significant association between sector and grant receipt (p = 0.0004).

This indicates that nonprofit sectors are not equally likely to receive state government funding after seeking it. As shown in the accompanying bar chart, organizations in the Arts, Culture, and Humanities (83.2%) and Human Services (81.7%) sectors had the highest success rates, while Religion Related (50.0%) and International (53.8%) organizations had the lowest. These differences suggest that sector type may influence access to public funding, even after controlling for application effort.

data04_cleaned <- data04 |>
  mutate(
    sector_group = case_when(
      ntee1 == "A" ~ "I. Arts, Culture, Humanities",
      ntee1 == "B" ~ "II. Education",
      ntee1 %in% c("C", "D") ~ "III. Environment & Animals",
      ntee1 %in% c("E", "F", "G", "H") ~ "IV. Health",
      ntee1 %in% c("I", "J", "K", "L", "M", "N", "O", "P") ~ "V. Human Services",
      ntee1 == "Q" ~ "VI. International",
      ntee1 %in% c("R", "S", "T", "U", "V", "W") ~ "VII. Public/Societal Benefit",
      ntee1 == "X" ~ "VIII. Religion Related",
      ntee1 == "Y" ~ "IX. Mutual/Membership Benefit",
      ntee1 == "Z" ~ "X. Unknown/Unclassified",
      TRUE ~ "Other"
    )
  )

# Filter to only those who sought a local government grant
data_sought <- data04_cleaned |>
  filter(FndRaise_StateGvtGrnt_Seek == 1)

# Create contingency table for receiving by sector
contingency_table <- table(data_sought$sector_group, data_sought$FndRaise_StateGvtGrnt_Rcv)

# Run chi-square test
chi_squared_result <- chisq.test(contingency_table)
## Warning in chisq.test(contingency_table): Chi-squared approximation may be
## incorrect
# Output
print(contingency_table)
##                               
##                                  0   1
##   I. Arts, Culture, Humanities  82 405
##   II. Education                 25  55
##   III. Environment & Animals    35  93
##   IV. Health                    29 101
##   V. Human Services            123 550
##   VI. International              6   7
##   VII. Public/Societal Benefit  40 104
##   VIII. Religion Related         1   1
print(chi_squared_result)
## 
##  Pearson's Chi-squared test
## 
## data:  contingency_table
## X-squared = 26.576, df = 7, p-value = 0.0003972
library(dplyr)
library(ggplot2)

# Filter to organizations that sought local government grants
data_sought <- data04_cleaned |>
  filter(FndRaise_StateGvtGrnt_Seek == 1)

# Calculate success rates per sector
success_by_sector <- data_sought |>
  group_by(sector_group) |>
  summarise(
    total_sought = n(),
    total_received = sum(FndRaise_StateGvtGrnt_Rcv == 1, na.rm = TRUE),
    success_rate = round(100 * total_received / total_sought, 1)
  ) |>
  arrange(desc(success_rate))

# Plot
ggplot(success_by_sector, aes(x = reorder(sector_group, success_rate), y = success_rate)) +
  geom_col(fill = "steelblue") +
  geom_text(aes(label = paste0(success_rate, "%")), hjust = -0.1, size = 3.5) +
  coord_flip() +
  labs(
    title = "Success Rate of Receiving State Government Grants (Among Seekers)",
    x = "Nonprofit Sector",
    y = "Success Rate (%)"
  ) +
  theme_minimal(base_size = 12) +
  ylim(0, 110)

seeking and recieving state gov grant- Weighted

A Rao-Scott chi-squared test was conducted to assess whether the proportion of nonprofits that received state government grants (among those that sought them) differed significantly across nonprofit sectors, while accounting for survey weights. The result was statistically significant (F = 3.57, df = 6.94, p = 0.0008), indicating that the success rate of receiving state government grants varies meaningfully by sector even after adjusting for sampling differences using the year4wt weight.

#weighted 
library(dplyr)
library(ggplot2)
library(survey)

# Step 1: Add sector groupings
data04_cleaned <- data04 |>
  mutate(
    sector_group = case_when(
      ntee1 == "A" ~ "I. Arts, Culture, Humanities",
      ntee1 == "B" ~ "II. Education",
      ntee1 %in% c("C", "D") ~ "III. Environment & Animals",
      ntee1 %in% c("E", "F", "G", "H") ~ "IV. Health",
      ntee1 %in% c("I", "J", "K", "L", "M", "N", "O", "P") ~ "V. Human Services",
      ntee1 == "Q" ~ "VI. International",
      ntee1 %in% c("R", "S", "T", "U", "V", "W") ~ "VII. Public/Societal Benefit",
      ntee1 == "X" ~ "VIII. Religion Related",
      ntee1 == "Y" ~ "IX. Mutual/Membership Benefit",
      ntee1 == "Z" ~ "X. Unknown/Unclassified",
      TRUE ~ "Other"
    )
  )

# Step 2: Filter to only those who sought state government grants
data_sought <- data04_cleaned |>
  filter(FndRaise_StateGvtGrnt_Seek == 1) |>
  mutate(
    FndRaise_StateGvtGrnt_Rcv = factor(FndRaise_StateGvtGrnt_Rcv, levels = c(0, 1)),
    sector_group = factor(sector_group)
  )

# Step 3: Define survey design using weights
design <- svydesign(
  ids = ~1,
  weights = ~year4wt,
  data = data_sought
)

# Step 4: Weighted chi-squared test
chi_result <- svychisq(~sector_group + FndRaise_StateGvtGrnt_Rcv, design = design)

# Step 5: Print test results
print(chi_result)
## 
##  Pearson's X^2: Rao & Scott adjustment
## 
## data:  svychisq(~sector_group + FndRaise_StateGvtGrnt_Rcv, design = design)
## F = 3.5677, ndf = 6.9425, ddf = 11496.7938, p-value = 0.0008056
# Step 6: Weighted success rate plot (optional but unweighted here for simplicity)
success_by_sector <- data_sought |>
  group_by(sector_group) |>
  summarise(
    total_sought = n(),
    total_received = sum(FndRaise_StateGvtGrnt_Rcv == 1, na.rm = TRUE),
    success_rate = round(100 * total_received / total_sought, 1)
  ) |>
  arrange(desc(success_rate))

ggplot(success_by_sector, aes(x = reorder(sector_group, success_rate), y = success_rate)) +
  geom_col(fill = "steelblue") +
  geom_text(aes(label = paste0(success_rate, "%")), hjust = -0.1, size = 3.5) +
  coord_flip() +
  labs(
    title = "Success Rate of Receiving State Government Grants (Among Seekers)",
    x = "Nonprofit Sector",
    y = "Success Rate (%)"
  ) +
  theme_minimal(base_size = 12) +
  ylim(0, 110)

seeking and recieving federal gov grant

  • Not weighted Among nonprofits that sought federal government grants, success rates varied by sector. For example, organizations in Public/Societal Benefit and Human Services sectors had the highest success rates (72.2% and 71.3%, respectively), while International and Health sectors had the lowest (44.4% and 56.7%).

These differences are statistically significant (p = 0.00039), suggesting that sector plays a role in federal funding outcomes even among those who applied.

  • Weighted A weighted chi-squared test using the Rao & Scott adjustment was conducted to examine whether the likelihood of receiving federal government grants differed across nonprofit sectors, among organizations that sought such funding. Accounting for sample weights (year4wt), the association was statistically significant (F = 3.72, adjusted df = 6.89, p = 0.00054). This suggests that some sectors had a significantly higher or lower success rate than others in securing federal grants after seeking them.
# Create sector groupings
data04_cleaned <- data04 |>
  mutate(
    sector_group = case_when(
      ntee1 == "A" ~ "I. Arts, Culture, Humanities",
      ntee1 == "B" ~ "II. Education",
      ntee1 %in% c("C", "D") ~ "III. Environment & Animals",
      ntee1 %in% c("E", "F", "G", "H") ~ "IV. Health",
      ntee1 %in% c("I", "J", "K", "L", "M", "N", "O", "P") ~ "V. Human Services",
      ntee1 == "Q" ~ "VI. International",
      ntee1 %in% c("R", "S", "T", "U", "V", "W") ~ "VII. Public/Societal Benefit",
      ntee1 == "X" ~ "VIII. Religion Related",
      ntee1 == "Y" ~ "IX. Mutual/Membership Benefit",
      ntee1 == "Z" ~ "X. Unknown/Unclassified",
      TRUE ~ "Other"
    )
  )

# Filter to those who sought federal grants (not those who received)
data_sought <- data04_cleaned |>
  filter(FndRaise_FedGvtGrnt_Seek == 1)

#Ensure 'received' column has both 0s and 1s for Chi-square to work
data_sought$FndRaise_FedGvtGrnt_Rcv <- factor(
  data_sought$FndRaise_FedGvtGrnt_Rcv, levels = c(0, 1)
)

#not weighted

# Build contingency table
contingency_table <- table(data_sought$sector_group, data_sought$FndRaise_FedGvtGrnt_Rcv)

# Run chi-square test
chi_squared_result <- chisq.test(contingency_table)
## Warning in chisq.test(contingency_table): Chi-squared approximation may be
## incorrect
# Output
print(contingency_table)
##                               
##                                  0   1
##   I. Arts, Culture, Humanities 118 161
##   II. Education                 17  29
##   III. Environment & Animals    38  62
##   IV. Health                    42  55
##   V. Human Services            149 370
##   VI. International             15  12
##   VII. Public/Societal Benefit  32  83
##   VIII. Religion Related         1   2
print(chi_squared_result)
## 
##  Pearson's Chi-squared test
## 
## data:  contingency_table
## X-squared = 26.639, df = 7, p-value = 0.0003869
#weighted

library(survey)

# Step 1: Create survey design object using year4wt
design <- svydesign(ids = ~1, data = data_sought, weights = ~year4wt)

# Step 2: Run weighted chi-squared test using Rao & Scott adjustment
svy_result <- svychisq(~ sector_group + FndRaise_FedGvtGrnt_Rcv, design = design)

# Step 3: Output result
print(svy_result)
## 
##  Pearson's X^2: Rao & Scott adjustment
## 
## data:  svychisq(~sector_group + FndRaise_FedGvtGrnt_Rcv, design = design)
## F = 3.7229, ndf = 6.8941, ddf = 8169.4502, p-value = 0.0005396
# Calculate success rate per sector
library(dplyr)
library(ggplot2)

success_by_sector <- data_sought |>
  group_by(sector_group) |>
  summarise(
    total_sought = n(),
    total_received = sum(FndRaise_FedGvtGrnt_Rcv == 1, na.rm = TRUE),
    success_rate = round(100 * total_received / total_sought, 1)
  ) |>
  arrange(desc(success_rate))

# Plot success rate
ggplot(success_by_sector, aes(x = reorder(sector_group, success_rate), y = success_rate)) +
  geom_col(fill = "steelblue") +
  geom_text(aes(label = paste0(success_rate, "%")), hjust = -0.1, size = 3.5) +
  coord_flip() +
  labs(
    title = "Success Rate of Receiving Federal Government Grants (Among Seekers)",
    x = "Nonprofit Sector",
    y = "Success Rate (%)"
  ) +
  theme_minimal(base_size = 12) +
  ylim(0, 110)

library(tidyr)
## 
## Attaching package: 'tidyr'
## The following objects are masked from 'package:Matrix':
## 
##     expand, pack, unpack
library(dplyr)

# Define relevant columns
grant_cols <- c("LocGvtGrnt", "StateGvtGrnt", "FedGvtGrnt")

# Create long-format data for modeling
long_data <- data04_cleaned |>
  pivot_longer(
    cols = starts_with("FndRaise_"),
    names_to = c("grant_type", ".value"),
    names_pattern = "FndRaise_(.*)_(Seek|Rcv)"
  ) |>
  filter(Seek == 1) |>  # Only include rows where the org applied
  rename(received = Rcv)

model <- glm(received ~ grant_type * sector_group,
             data = long_data,
             family = "binomial")

summary(model)
## 
## Call:
## glm(formula = received ~ grant_type * sector_group, family = "binomial", 
##     data = long_data)
## 
## Coefficients: (6 not defined because of singularities)
##                                                                      Estimate
## (Intercept)                                                          1.450456
## grant_typeCombFedCmpgn                                              -2.366747
## grant_typeCorp_Found_Grnt                                            0.264930
## grant_typeDAF                                                        0.915308
## grant_typeFedGvtCntrct                                              -1.768910
## grant_typeFedGvtGrnt                                                -1.139737
## grant_typeLocGvtCntrct                                              -0.469627
## grant_typeLocGvtGrnt                                                 0.375041
## grant_typeOthrGvngPrgrm                                             -0.351844
## grant_typePFGrnt                                                     0.353425
## grant_typeStateGvtCntrct                                            -0.757309
## grant_typeStateGvtGrnt                                               0.146712
## grant_typeUntdWy                                                    -0.197693
## sector_groupII. Education                                           -0.489994
## sector_groupIII. Environment & Animals                              -0.046035
## sector_groupIV. Health                                              -0.332976
## sector_groupV. Human Services                                        0.008942
## sector_groupVI. International                                       -1.067464
## sector_groupVII. Public/Societal Benefit                             0.046652
## sector_groupVIII. Religion Related                                  -1.044991
## grant_typeCombFedCmpgn:sector_groupII. Education                    14.972352
## grant_typeCorp_Found_Grnt:sector_groupII. Education                  0.039205
## grant_typeDAF:sector_groupII. Education                             -0.489475
## grant_typeFedGvtCntrct:sector_groupII. Education                    14.374515
## grant_typeFedGvtGrnt:sector_groupII. Education                       0.713357
## grant_typeLocGvtCntrct:sector_groupII. Education                     1.501595
## grant_typeLocGvtGrnt:sector_groupII. Education                      -0.584087
## grant_typeOthrGvngPrgrm:sector_groupII. Education                    1.588607
## grant_typePFGrnt:sector_groupII. Education                           0.304210
## grant_typeStateGvtCntrct:sector_groupII. Education                   2.630061
## grant_typeStateGvtGrnt:sector_groupII. Education                    -0.318716
## grant_typeUntdWy:sector_groupII. Education                           0.623526
## grant_typeCombFedCmpgn:sector_groupIII. Environment & Animals        2.261608
## grant_typeCorp_Found_Grnt:sector_groupIII. Environment & Animals    -0.001074
## grant_typeDAF:sector_groupIII. Environment & Animals                -0.373819
## grant_typeFedGvtCntrct:sector_groupIII. Environment & Animals        1.057635
## grant_typeFedGvtGrnt:sector_groupIII. Environment & Animals          0.224863
## grant_typeLocGvtCntrct:sector_groupIII. Environment & Animals        0.832867
## grant_typeLocGvtGrnt:sector_groupIII. Environment & Animals         -0.575490
## grant_typeOthrGvngPrgrm:sector_groupIII. Environment & Animals      -0.851907
## grant_typePFGrnt:sector_groupIII. Environment & Animals              0.372687
## grant_typeStateGvtCntrct:sector_groupIII. Environment & Animals      0.451500
## grant_typeStateGvtGrnt:sector_groupIII. Environment & Animals       -0.573882
## grant_typeUntdWy:sector_groupIII. Environment & Animals              0.061783
## grant_typeCombFedCmpgn:sector_groupIV. Health                        0.892591
## grant_typeCorp_Found_Grnt:sector_groupIV. Health                    -0.054224
## grant_typeDAF:sector_groupIV. Health                                -0.566451
## grant_typeFedGvtCntrct:sector_groupIV. Health                        1.344576
## grant_typeFedGvtGrnt:sector_groupIV. Health                          0.291919
## grant_typeLocGvtCntrct:sector_groupIV. Health                        0.393600
## grant_typeLocGvtGrnt:sector_groupIV. Health                          0.041408
## grant_typeOthrGvngPrgrm:sector_groupIV. Health                      -0.330319
## grant_typePFGrnt:sector_groupIV. Health                              0.036533
## grant_typeStateGvtCntrct:sector_groupIV. Health                      1.056894
## grant_typeStateGvtGrnt:sector_groupIV. Health                       -0.016368
## grant_typeUntdWy:sector_groupIV. Health                              0.160133
## grant_typeCombFedCmpgn:sector_groupV. Human Services                 1.223686
## grant_typeCorp_Found_Grnt:sector_groupV. Human Services              0.145104
## grant_typeDAF:sector_groupV. Human Services                         -0.635912
## grant_typeFedGvtCntrct:sector_groupV. Human Services                 0.846313
## grant_typeFedGvtGrnt:sector_groupV. Human Services                   0.589895
## grant_typeLocGvtCntrct:sector_groupV. Human Services                 0.195273
## grant_typeLocGvtGrnt:sector_groupV. Human Services                  -0.426851
## grant_typeOthrGvngPrgrm:sector_groupV. Human Services               -0.206768
## grant_typePFGrnt:sector_groupV. Human Services                       0.194088
## grant_typeStateGvtCntrct:sector_groupV. Human Services               0.580136
## grant_typeStateGvtGrnt:sector_groupV. Human Services                -0.108376
## grant_typeUntdWy:sector_groupV. Human Services                       0.143432
## grant_typeCombFedCmpgn:sector_groupVI. International                 2.389220
## grant_typeCorp_Found_Grnt:sector_groupVI. International              0.565100
## grant_typeDAF:sector_groupVI. International                          0.419352
## grant_typeFedGvtCntrct:sector_groupVI. International               -12.180149
## grant_typeFedGvtGrnt:sector_groupVI. International                   0.533601
## grant_typeLocGvtCntrct:sector_groupVI. International                 1.696073
## grant_typeLocGvtGrnt:sector_groupVI. International                  -0.064886
## grant_typeOthrGvngPrgrm:sector_groupVI. International                0.528468
## grant_typePFGrnt:sector_groupVI. International                       0.430018
## grant_typeStateGvtCntrct:sector_groupVI. International                     NA
## grant_typeStateGvtGrnt:sector_groupVI. International                -0.375553
## grant_typeUntdWy:sector_groupVI. International                      -0.590764
## grant_typeCombFedCmpgn:sector_groupVII. Public/Societal Benefit     -0.111191
## grant_typeCorp_Found_Grnt:sector_groupVII. Public/Societal Benefit   0.258906
## grant_typeDAF:sector_groupVII. Public/Societal Benefit              -0.908339
## grant_typeFedGvtCntrct:sector_groupVII. Public/Societal Benefit      1.033941
## grant_typeFedGvtGrnt:sector_groupVII. Public/Societal Benefit        0.595733
## grant_typeLocGvtCntrct:sector_groupVII. Public/Societal Benefit      0.581956
## grant_typeLocGvtGrnt:sector_groupVII. Public/Societal Benefit       -0.510347
## grant_typeOthrGvngPrgrm:sector_groupVII. Public/Societal Benefit    -0.788590
## grant_typePFGrnt:sector_groupVII. Public/Societal Benefit           -0.084351
## grant_typeStateGvtCntrct:sector_groupVII. Public/Societal Benefit    0.908859
## grant_typeStateGvtGrnt:sector_groupVII. Public/Societal Benefit     -0.688309
## grant_typeUntdWy:sector_groupVII. Public/Societal Benefit            0.724966
## grant_typeCombFedCmpgn:sector_groupVIII. Religion Related                  NA
## grant_typeCorp_Found_Grnt:sector_groupVIII. Religion Related        12.895671
## grant_typeDAF:sector_groupVIII. Religion Related                    -0.222161
## grant_typeFedGvtCntrct:sector_groupVIII. Religion Related                  NA
## grant_typeFedGvtGrnt:sector_groupVIII. Religion Related              1.427419
## grant_typeLocGvtCntrct:sector_groupVIII. Religion Related                  NA
## grant_typeLocGvtGrnt:sector_groupVIII. Religion Related             -0.780506
## grant_typeOthrGvngPrgrm:sector_groupVIII. Religion Related                 NA
## grant_typePFGrnt:sector_groupVIII. Religion Related                  0.339723
## grant_typeStateGvtCntrct:sector_groupVIII. Religion Related                NA
## grant_typeStateGvtGrnt:sector_groupVIII. Religion Related           -0.552177
## grant_typeUntdWy:sector_groupVIII. Religion Related                 13.358295
##                                                                    Std. Error
## (Intercept)                                                          0.121955
## grant_typeCombFedCmpgn                                               0.845502
## grant_typeCorp_Found_Grnt                                            0.179512
## grant_typeDAF                                                        0.249866
## grant_typeFedGvtCntrct                                               0.480398
## grant_typeFedGvtGrnt                                                 0.171927
## grant_typeLocGvtCntrct                                               0.302096
## grant_typeLocGvtGrnt                                                 0.178742
## grant_typeOthrGvngPrgrm                                              0.426075
## grant_typePFGrnt                                                     0.170517
## grant_typeStateGvtCntrct                                             0.373996
## grant_typeStateGvtGrnt                                               0.171864
## grant_typeUntdWy                                                     0.349308
## sector_groupII. Education                                            0.243879
## sector_groupIII. Environment & Animals                               0.212724
## sector_groupIV. Health                                               0.229761
## sector_groupV. Human Services                                        0.147636
## sector_groupVI. International                                        0.356363
## sector_groupVII. Public/Societal Benefit                             0.230469
## sector_groupVIII. Religion Related                                   0.920981
## grant_typeCombFedCmpgn:sector_groupII. Education                   239.444740
## grant_typeCorp_Found_Grnt:sector_groupII. Education                  0.360915
## grant_typeDAF:sector_groupII. Education                              0.481702
## grant_typeFedGvtCntrct:sector_groupII. Education                   309.120228
## grant_typeFedGvtGrnt:sector_groupII. Education                       0.409230
## grant_typeLocGvtCntrct:sector_groupII. Education                     0.717394
## grant_typeLocGvtGrnt:sector_groupII. Education                       0.367995
## grant_typeOthrGvngPrgrm:sector_groupII. Education                    1.156397
## grant_typePFGrnt:sector_groupII. Education                           0.354653
## grant_typeStateGvtCntrct:sector_groupII. Education                   1.115034
## grant_typeStateGvtGrnt:sector_groupII. Education                     0.363762
## grant_typeUntdWy:sector_groupII. Education                           0.568216
## grant_typeCombFedCmpgn:sector_groupIII. Environment & Animals        1.081431
## grant_typeCorp_Found_Grnt:sector_groupIII. Environment & Animals     0.314038
## grant_typeDAF:sector_groupIII. Environment & Animals                 0.400048
## grant_typeFedGvtCntrct:sector_groupIII. Environment & Animals        0.689526
## grant_typeFedGvtGrnt:sector_groupIII. Environment & Animals          0.319972
## grant_typeLocGvtCntrct:sector_groupIII. Environment & Animals        0.537483
## grant_typeLocGvtGrnt:sector_groupIII. Environment & Animals          0.318937
## grant_typeOthrGvngPrgrm:sector_groupIII. Environment & Animals       0.643380
## grant_typePFGrnt:sector_groupIII. Environment & Animals              0.309102
## grant_typeStateGvtCntrct:sector_groupIII. Environment & Animals      0.580446
## grant_typeStateGvtGrnt:sector_groupIII. Environment & Animals        0.315023
## grant_typeUntdWy:sector_groupIII. Environment & Animals              0.542914
## grant_typeCombFedCmpgn:sector_groupIV. Health                        0.997821
## grant_typeCorp_Found_Grnt:sector_groupIV. Health                     0.333087
## grant_typeDAF:sector_groupIV. Health                                 0.427085
## grant_typeFedGvtCntrct:sector_groupIV. Health                        0.694971
## grant_typeFedGvtGrnt:sector_groupIV. Health                          0.330859
## grant_typeLocGvtCntrct:sector_groupIV. Health                        0.491858
## grant_typeLocGvtGrnt:sector_groupIV. Health                          0.353729
## grant_typeOthrGvngPrgrm:sector_groupIV. Health                       0.607610
## grant_typePFGrnt:sector_groupIV. Health                              0.322503
## grant_typeStateGvtCntrct:sector_groupIV. Health                      0.577142
## grant_typeStateGvtGrnt:sector_groupIV. Health                        0.334422
## grant_typeUntdWy:sector_groupIV. Health                              0.484104
## grant_typeCombFedCmpgn:sector_groupV. Human Services                 0.872927
## grant_typeCorp_Found_Grnt:sector_groupV. Human Services              0.219149
## grant_typeDAF:sector_groupV. Human Services                          0.288710
## grant_typeFedGvtCntrct:sector_groupV. Human Services                 0.528589
## grant_typeFedGvtGrnt:sector_groupV. Human Services                   0.214234
## grant_typeLocGvtCntrct:sector_groupV. Human Services                 0.354102
## grant_typeLocGvtGrnt:sector_groupV. Human Services                   0.217061
## grant_typeOthrGvngPrgrm:sector_groupV. Human Services                0.464227
## grant_typePFGrnt:sector_groupV. Human Services                       0.210868
## grant_typeStateGvtCntrct:sector_groupV. Human Services               0.420124
## grant_typeStateGvtGrnt:sector_groupV. Human Services                 0.215428
## grant_typeUntdWy:sector_groupV. Human Services                       0.377459
## grant_typeCombFedCmpgn:sector_groupVI. International                 1.288537
## grant_typeCorp_Found_Grnt:sector_groupVI. International              0.512135
## grant_typeDAF:sector_groupVI. International                          0.585707
## grant_typeFedGvtCntrct:sector_groupVI. International               309.120337
## grant_typeFedGvtGrnt:sector_groupVI. International                   0.540074
## grant_typeLocGvtCntrct:sector_groupVI. International                 1.184645
## grant_typeLocGvtGrnt:sector_groupVI. International                   0.666386
## grant_typeOthrGvngPrgrm:sector_groupVI. International                0.828564
## grant_typePFGrnt:sector_groupVI. International                       0.458500
## grant_typeStateGvtCntrct:sector_groupVI. International                     NA
## grant_typeStateGvtGrnt:sector_groupVI. International                 0.671701
## grant_typeUntdWy:sector_groupVI. International                       1.033185
## grant_typeCombFedCmpgn:sector_groupVII. Public/Societal Benefit      1.100659
## grant_typeCorp_Found_Grnt:sector_groupVII. Public/Societal Benefit   0.349208
## grant_typeDAF:sector_groupVII. Public/Societal Benefit               0.410582
## grant_typeFedGvtCntrct:sector_groupVII. Public/Societal Benefit      0.691772
## grant_typeFedGvtGrnt:sector_groupVII. Public/Societal Benefit        0.333317
## grant_typeLocGvtCntrct:sector_groupVII. Public/Societal Benefit      0.512678
## grant_typeLocGvtGrnt:sector_groupVII. Public/Societal Benefit        0.332737
## grant_typeOthrGvngPrgrm:sector_groupVII. Public/Societal Benefit     0.680176
## grant_typePFGrnt:sector_groupVII. Public/Societal Benefit            0.320630
## grant_typeStateGvtCntrct:sector_groupVII. Public/Societal Benefit    0.645428
## grant_typeStateGvtGrnt:sector_groupVII. Public/Societal Benefit      0.319993
## grant_typeUntdWy:sector_groupVII. Public/Societal Benefit            0.567436
## grant_typeCombFedCmpgn:sector_groupVIII. Religion Related                  NA
## grant_typeCorp_Found_Grnt:sector_groupVIII. Religion Related       239.444961
## grant_typeDAF:sector_groupVIII. Religion Related                     1.493017
## grant_typeFedGvtCntrct:sector_groupVIII. Religion Related                  NA
## grant_typeFedGvtGrnt:sector_groupVIII. Religion Related              1.537170
## grant_typeLocGvtCntrct:sector_groupVIII. Religion Related                  NA
## grant_typeLocGvtGrnt:sector_groupVIII. Religion Related              1.365753
## grant_typeOthrGvngPrgrm:sector_groupVIII. Religion Related                 NA
## grant_typePFGrnt:sector_groupVIII. Religion Related                  1.236558
## grant_typeStateGvtCntrct:sector_groupVIII. Religion Related                NA
## grant_typeStateGvtGrnt:sector_groupVIII. Religion Related            1.692002
## grant_typeUntdWy:sector_groupVIII. Religion Related                378.594130
##                                                                    z value
## (Intercept)                                                         11.893
## grant_typeCombFedCmpgn                                              -2.799
## grant_typeCorp_Found_Grnt                                            1.476
## grant_typeDAF                                                        3.663
## grant_typeFedGvtCntrct                                              -3.682
## grant_typeFedGvtGrnt                                                -6.629
## grant_typeLocGvtCntrct                                              -1.555
## grant_typeLocGvtGrnt                                                 2.098
## grant_typeOthrGvngPrgrm                                             -0.826
## grant_typePFGrnt                                                     2.073
## grant_typeStateGvtCntrct                                            -2.025
## grant_typeStateGvtGrnt                                               0.854
## grant_typeUntdWy                                                    -0.566
## sector_groupII. Education                                           -2.009
## sector_groupIII. Environment & Animals                              -0.216
## sector_groupIV. Health                                              -1.449
## sector_groupV. Human Services                                        0.061
## sector_groupVI. International                                       -2.995
## sector_groupVII. Public/Societal Benefit                             0.202
## sector_groupVIII. Religion Related                                  -1.135
## grant_typeCombFedCmpgn:sector_groupII. Education                     0.063
## grant_typeCorp_Found_Grnt:sector_groupII. Education                  0.109
## grant_typeDAF:sector_groupII. Education                             -1.016
## grant_typeFedGvtCntrct:sector_groupII. Education                     0.047
## grant_typeFedGvtGrnt:sector_groupII. Education                       1.743
## grant_typeLocGvtCntrct:sector_groupII. Education                     2.093
## grant_typeLocGvtGrnt:sector_groupII. Education                      -1.587
## grant_typeOthrGvngPrgrm:sector_groupII. Education                    1.374
## grant_typePFGrnt:sector_groupII. Education                           0.858
## grant_typeStateGvtCntrct:sector_groupII. Education                   2.359
## grant_typeStateGvtGrnt:sector_groupII. Education                    -0.876
## grant_typeUntdWy:sector_groupII. Education                           1.097
## grant_typeCombFedCmpgn:sector_groupIII. Environment & Animals        2.091
## grant_typeCorp_Found_Grnt:sector_groupIII. Environment & Animals    -0.003
## grant_typeDAF:sector_groupIII. Environment & Animals                -0.934
## grant_typeFedGvtCntrct:sector_groupIII. Environment & Animals        1.534
## grant_typeFedGvtGrnt:sector_groupIII. Environment & Animals          0.703
## grant_typeLocGvtCntrct:sector_groupIII. Environment & Animals        1.550
## grant_typeLocGvtGrnt:sector_groupIII. Environment & Animals         -1.804
## grant_typeOthrGvngPrgrm:sector_groupIII. Environment & Animals      -1.324
## grant_typePFGrnt:sector_groupIII. Environment & Animals              1.206
## grant_typeStateGvtCntrct:sector_groupIII. Environment & Animals      0.778
## grant_typeStateGvtGrnt:sector_groupIII. Environment & Animals       -1.822
## grant_typeUntdWy:sector_groupIII. Environment & Animals              0.114
## grant_typeCombFedCmpgn:sector_groupIV. Health                        0.895
## grant_typeCorp_Found_Grnt:sector_groupIV. Health                    -0.163
## grant_typeDAF:sector_groupIV. Health                                -1.326
## grant_typeFedGvtCntrct:sector_groupIV. Health                        1.935
## grant_typeFedGvtGrnt:sector_groupIV. Health                          0.882
## grant_typeLocGvtCntrct:sector_groupIV. Health                        0.800
## grant_typeLocGvtGrnt:sector_groupIV. Health                          0.117
## grant_typeOthrGvngPrgrm:sector_groupIV. Health                      -0.544
## grant_typePFGrnt:sector_groupIV. Health                              0.113
## grant_typeStateGvtCntrct:sector_groupIV. Health                      1.831
## grant_typeStateGvtGrnt:sector_groupIV. Health                       -0.049
## grant_typeUntdWy:sector_groupIV. Health                              0.331
## grant_typeCombFedCmpgn:sector_groupV. Human Services                 1.402
## grant_typeCorp_Found_Grnt:sector_groupV. Human Services              0.662
## grant_typeDAF:sector_groupV. Human Services                         -2.203
## grant_typeFedGvtCntrct:sector_groupV. Human Services                 1.601
## grant_typeFedGvtGrnt:sector_groupV. Human Services                   2.754
## grant_typeLocGvtCntrct:sector_groupV. Human Services                 0.551
## grant_typeLocGvtGrnt:sector_groupV. Human Services                  -1.967
## grant_typeOthrGvngPrgrm:sector_groupV. Human Services               -0.445
## grant_typePFGrnt:sector_groupV. Human Services                       0.920
## grant_typeStateGvtCntrct:sector_groupV. Human Services               1.381
## grant_typeStateGvtGrnt:sector_groupV. Human Services                -0.503
## grant_typeUntdWy:sector_groupV. Human Services                       0.380
## grant_typeCombFedCmpgn:sector_groupVI. International                 1.854
## grant_typeCorp_Found_Grnt:sector_groupVI. International              1.103
## grant_typeDAF:sector_groupVI. International                          0.716
## grant_typeFedGvtCntrct:sector_groupVI. International                -0.039
## grant_typeFedGvtGrnt:sector_groupVI. International                   0.988
## grant_typeLocGvtCntrct:sector_groupVI. International                 1.432
## grant_typeLocGvtGrnt:sector_groupVI. International                  -0.097
## grant_typeOthrGvngPrgrm:sector_groupVI. International                0.638
## grant_typePFGrnt:sector_groupVI. International                       0.938
## grant_typeStateGvtCntrct:sector_groupVI. International                  NA
## grant_typeStateGvtGrnt:sector_groupVI. International                -0.559
## grant_typeUntdWy:sector_groupVI. International                      -0.572
## grant_typeCombFedCmpgn:sector_groupVII. Public/Societal Benefit     -0.101
## grant_typeCorp_Found_Grnt:sector_groupVII. Public/Societal Benefit   0.741
## grant_typeDAF:sector_groupVII. Public/Societal Benefit              -2.212
## grant_typeFedGvtCntrct:sector_groupVII. Public/Societal Benefit      1.495
## grant_typeFedGvtGrnt:sector_groupVII. Public/Societal Benefit        1.787
## grant_typeLocGvtCntrct:sector_groupVII. Public/Societal Benefit      1.135
## grant_typeLocGvtGrnt:sector_groupVII. Public/Societal Benefit       -1.534
## grant_typeOthrGvngPrgrm:sector_groupVII. Public/Societal Benefit    -1.159
## grant_typePFGrnt:sector_groupVII. Public/Societal Benefit           -0.263
## grant_typeStateGvtCntrct:sector_groupVII. Public/Societal Benefit    1.408
## grant_typeStateGvtGrnt:sector_groupVII. Public/Societal Benefit     -2.151
## grant_typeUntdWy:sector_groupVII. Public/Societal Benefit            1.278
## grant_typeCombFedCmpgn:sector_groupVIII. Religion Related               NA
## grant_typeCorp_Found_Grnt:sector_groupVIII. Religion Related         0.054
## grant_typeDAF:sector_groupVIII. Religion Related                    -0.149
## grant_typeFedGvtCntrct:sector_groupVIII. Religion Related               NA
## grant_typeFedGvtGrnt:sector_groupVIII. Religion Related              0.929
## grant_typeLocGvtCntrct:sector_groupVIII. Religion Related               NA
## grant_typeLocGvtGrnt:sector_groupVIII. Religion Related             -0.571
## grant_typeOthrGvngPrgrm:sector_groupVIII. Religion Related              NA
## grant_typePFGrnt:sector_groupVIII. Religion Related                  0.275
## grant_typeStateGvtCntrct:sector_groupVIII. Religion Related             NA
## grant_typeStateGvtGrnt:sector_groupVIII. Religion Related           -0.326
## grant_typeUntdWy:sector_groupVIII. Religion Related                  0.035
##                                                                    Pr(>|z|)    
## (Intercept)                                                         < 2e-16 ***
## grant_typeCombFedCmpgn                                             0.005123 ** 
## grant_typeCorp_Found_Grnt                                          0.139987    
## grant_typeDAF                                                      0.000249 ***
## grant_typeFedGvtCntrct                                             0.000231 ***
## grant_typeFedGvtGrnt                                               3.38e-11 ***
## grant_typeLocGvtCntrct                                             0.120050    
## grant_typeLocGvtGrnt                                               0.035885 *  
## grant_typeOthrGvngPrgrm                                            0.408929    
## grant_typePFGrnt                                                   0.038204 *  
## grant_typeStateGvtCntrct                                           0.042876 *  
## grant_typeStateGvtGrnt                                             0.393300    
## grant_typeUntdWy                                                   0.571423    
## sector_groupII. Education                                          0.044519 *  
## sector_groupIII. Environment & Animals                             0.828672    
## sector_groupIV. Health                                             0.147275    
## sector_groupV. Human Services                                      0.951702    
## sector_groupVI. International                                      0.002740 ** 
## sector_groupVII. Public/Societal Benefit                           0.839586    
## sector_groupVIII. Religion Related                                 0.256522    
## grant_typeCombFedCmpgn:sector_groupII. Education                   0.950141    
## grant_typeCorp_Found_Grnt:sector_groupII. Education                0.913498    
## grant_typeDAF:sector_groupII. Education                            0.309564    
## grant_typeFedGvtCntrct:sector_groupII. Education                   0.962911    
## grant_typeFedGvtGrnt:sector_groupII. Education                     0.081304 .  
## grant_typeLocGvtCntrct:sector_groupII. Education                   0.036338 *  
## grant_typeLocGvtGrnt:sector_groupII. Education                     0.112464    
## grant_typeOthrGvngPrgrm:sector_groupII. Education                  0.169518    
## grant_typePFGrnt:sector_groupII. Education                         0.391022    
## grant_typeStateGvtCntrct:sector_groupII. Education                 0.018338 *  
## grant_typeStateGvtGrnt:sector_groupII. Education                   0.380940    
## grant_typeUntdWy:sector_groupII. Education                         0.272493    
## grant_typeCombFedCmpgn:sector_groupIII. Environment & Animals      0.036500 *  
## grant_typeCorp_Found_Grnt:sector_groupIII. Environment & Animals   0.997272    
## grant_typeDAF:sector_groupIII. Environment & Animals               0.350079    
## grant_typeFedGvtCntrct:sector_groupIII. Environment & Animals      0.125064    
## grant_typeFedGvtGrnt:sector_groupIII. Environment & Animals        0.482206    
## grant_typeLocGvtCntrct:sector_groupIII. Environment & Animals      0.121245    
## grant_typeLocGvtGrnt:sector_groupIII. Environment & Animals        0.071168 .  
## grant_typeOthrGvngPrgrm:sector_groupIII. Environment & Animals     0.185466    
## grant_typePFGrnt:sector_groupIII. Environment & Animals            0.227930    
## grant_typeStateGvtCntrct:sector_groupIII. Environment & Animals    0.436658    
## grant_typeStateGvtGrnt:sector_groupIII. Environment & Animals      0.068499 .  
## grant_typeUntdWy:sector_groupIII. Environment & Animals            0.909397    
## grant_typeCombFedCmpgn:sector_groupIV. Health                      0.371033    
## grant_typeCorp_Found_Grnt:sector_groupIV. Health                   0.870681    
## grant_typeDAF:sector_groupIV. Health                               0.184734    
## grant_typeFedGvtCntrct:sector_groupIV. Health                      0.053024 .  
## grant_typeFedGvtGrnt:sector_groupIV. Health                        0.377610    
## grant_typeLocGvtCntrct:sector_groupIV. Health                      0.423577    
## grant_typeLocGvtGrnt:sector_groupIV. Health                        0.906811    
## grant_typeOthrGvngPrgrm:sector_groupIV. Health                     0.586692    
## grant_typePFGrnt:sector_groupIV. Health                            0.909808    
## grant_typeStateGvtCntrct:sector_groupIV. Health                    0.067063 .  
## grant_typeStateGvtGrnt:sector_groupIV. Health                      0.960965    
## grant_typeUntdWy:sector_groupIV. Health                            0.740809    
## grant_typeCombFedCmpgn:sector_groupV. Human Services               0.160969    
## grant_typeCorp_Found_Grnt:sector_groupV. Human Services            0.507893    
## grant_typeDAF:sector_groupV. Human Services                        0.027623 *  
## grant_typeFedGvtCntrct:sector_groupV. Human Services               0.109359    
## grant_typeFedGvtGrnt:sector_groupV. Human Services                 0.005896 ** 
## grant_typeLocGvtCntrct:sector_groupV. Human Services               0.581318    
## grant_typeLocGvtGrnt:sector_groupV. Human Services                 0.049240 *  
## grant_typeOthrGvngPrgrm:sector_groupV. Human Services              0.656028    
## grant_typePFGrnt:sector_groupV. Human Services                     0.357352    
## grant_typeStateGvtCntrct:sector_groupV. Human Services             0.167319    
## grant_typeStateGvtGrnt:sector_groupV. Human Services               0.614912    
## grant_typeUntdWy:sector_groupV. Human Services                     0.703950    
## grant_typeCombFedCmpgn:sector_groupVI. International               0.063709 .  
## grant_typeCorp_Found_Grnt:sector_groupVI. International            0.269844    
## grant_typeDAF:sector_groupVI. International                        0.474007    
## grant_typeFedGvtCntrct:sector_groupVI. International               0.968569    
## grant_typeFedGvtGrnt:sector_groupVI. International                 0.323146    
## grant_typeLocGvtCntrct:sector_groupVI. International               0.152226    
## grant_typeLocGvtGrnt:sector_groupVI. International                 0.922432    
## grant_typeOthrGvngPrgrm:sector_groupVI. International              0.523596    
## grant_typePFGrnt:sector_groupVI. International                     0.348306    
## grant_typeStateGvtCntrct:sector_groupVI. International                   NA    
## grant_typeStateGvtGrnt:sector_groupVI. International               0.576088    
## grant_typeUntdWy:sector_groupVI. International                     0.567465    
## grant_typeCombFedCmpgn:sector_groupVII. Public/Societal Benefit    0.919533    
## grant_typeCorp_Found_Grnt:sector_groupVII. Public/Societal Benefit 0.458444    
## grant_typeDAF:sector_groupVII. Public/Societal Benefit             0.026944 *  
## grant_typeFedGvtCntrct:sector_groupVII. Public/Societal Benefit    0.135012    
## grant_typeFedGvtGrnt:sector_groupVII. Public/Societal Benefit      0.073891 .  
## grant_typeLocGvtCntrct:sector_groupVII. Public/Societal Benefit    0.256320    
## grant_typeLocGvtGrnt:sector_groupVII. Public/Societal Benefit      0.125083    
## grant_typeOthrGvngPrgrm:sector_groupVII. Public/Societal Benefit   0.246297    
## grant_typePFGrnt:sector_groupVII. Public/Societal Benefit          0.792491    
## grant_typeStateGvtCntrct:sector_groupVII. Public/Societal Benefit  0.159087    
## grant_typeStateGvtGrnt:sector_groupVII. Public/Societal Benefit    0.031475 *  
## grant_typeUntdWy:sector_groupVII. Public/Societal Benefit          0.201384    
## grant_typeCombFedCmpgn:sector_groupVIII. Religion Related                NA    
## grant_typeCorp_Found_Grnt:sector_groupVIII. Religion Related       0.957049    
## grant_typeDAF:sector_groupVIII. Religion Related                   0.881712    
## grant_typeFedGvtCntrct:sector_groupVIII. Religion Related                NA    
## grant_typeFedGvtGrnt:sector_groupVIII. Religion Related            0.353096    
## grant_typeLocGvtCntrct:sector_groupVIII. Religion Related                NA    
## grant_typeLocGvtGrnt:sector_groupVIII. Religion Related            0.567671    
## grant_typeOthrGvngPrgrm:sector_groupVIII. Religion Related               NA    
## grant_typePFGrnt:sector_groupVIII. Religion Related                0.783522    
## grant_typeStateGvtCntrct:sector_groupVIII. Religion Related              NA    
## grant_typeStateGvtGrnt:sector_groupVIII. Religion Related          0.744163    
## grant_typeUntdWy:sector_groupVIII. Religion Related                0.971853    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 14731  on 14881  degrees of freedom
## Residual deviance: 14156  on 14784  degrees of freedom
## AIC: 14352
## 
## Number of Fisher Scoring iterations: 12
model1 <- glm(received ~ grant_type + sector_group,
             data = long_data,
             family = "binomial")

summary(model1) 
## 
## Call:
## glm(formula = received ~ grant_type + sector_group, family = "binomial", 
##     data = long_data)
## 
## Coefficients:
##                                           Estimate Std. Error z value Pr(>|z|)
## (Intercept)                               1.423912   0.068922  20.660  < 2e-16
## grant_typeCombFedCmpgn                   -1.136218   0.168827  -6.730 1.70e-11
## grant_typeCorp_Found_Grnt                 0.367000   0.081999   4.476 7.62e-06
## grant_typeDAF                             0.452996   0.098587   4.595 4.33e-06
## grant_typeFedGvtCntrct                   -0.892351   0.159036  -5.611 2.01e-08
## grant_typeFedGvtGrnt                     -0.742049   0.082266  -9.020  < 2e-16
## grant_typeLocGvtCntrct                   -0.086346   0.127049  -0.680 0.496743
## grant_typeLocGvtGrnt                      0.066873   0.081906   0.816 0.414235
## grant_typeOthrGvngPrgrm                  -0.562124   0.137581  -4.086 4.39e-05
## grant_typePFGrnt                          0.498039   0.079262   6.283 3.31e-10
## grant_typeStateGvtCntrct                 -0.092401   0.140351  -0.658 0.510311
## grant_typeStateGvtGrnt                   -0.029567   0.082142  -0.360 0.718882
## grant_typeUntdWy                         -0.004084   0.107425  -0.038 0.969674
## sector_groupII. Education                -0.328253   0.100813  -3.256 0.001130
## sector_groupIII. Environment & Animals   -0.076819   0.083051  -0.925 0.354985
## sector_groupIV. Health                   -0.290530   0.084894  -3.422 0.000621
## sector_groupV. Human Services             0.035251   0.056641   0.622 0.533704
## sector_groupVI. International            -0.729563   0.137634  -5.301 1.15e-07
## sector_groupVII. Public/Societal Benefit -0.029306   0.085204  -0.344 0.730879
## sector_groupVIII. Religion Related       -0.586994   0.399439  -1.470 0.141685
##                                             
## (Intercept)                              ***
## grant_typeCombFedCmpgn                   ***
## grant_typeCorp_Found_Grnt                ***
## grant_typeDAF                            ***
## grant_typeFedGvtCntrct                   ***
## grant_typeFedGvtGrnt                     ***
## grant_typeLocGvtCntrct                      
## grant_typeLocGvtGrnt                        
## grant_typeOthrGvngPrgrm                  ***
## grant_typePFGrnt                         ***
## grant_typeStateGvtCntrct                    
## grant_typeStateGvtGrnt                      
## grant_typeUntdWy                            
## sector_groupII. Education                ** 
## sector_groupIII. Environment & Animals      
## sector_groupIV. Health                   ***
## sector_groupV. Human Services               
## sector_groupVI. International            ***
## sector_groupVII. Public/Societal Benefit    
## sector_groupVIII. Religion Related          
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 14731  on 14881  degrees of freedom
## Residual deviance: 14292  on 14862  degrees of freedom
## AIC: 14332
## 
## Number of Fisher Scoring iterations: 4
received ~ grant_type + sector_group
## received ~ grant_type + sector_group

Difference in p and f values for the three grant types

library(knitr)
library(dplyr)

tribble(
  ~`Grant Type`, ~`F Statistic`, ~`Degrees of Freedom`, ~`p-value`, ~`Significance`,
  "Local Government Grants", 2.78, "df = 6.90, 12,236", 0.0072, "p < 0.01",
  "State Government Grants", 3.57, "df = 6.94, 11,497", 0.00081, "p < 0.001",
  "Federal Government Grants", 3.72, "df = 6.89, 8,169", 0.00054, "p < 0.001"
) %>%
  kable(caption = "Summary of Weighted Chi-Squared Tests by Grant Type")
Summary of Weighted Chi-Squared Tests by Grant Type
Grant Type F Statistic Degrees of Freedom p-value Significance
Local Government Grants 2.78 df = 6.90, 12,236 0.00720 p < 0.01
State Government Grants 3.57 df = 6.94, 11,497 0.00081 p < 0.001
Federal Government Grants 3.72 df = 6.89, 8,169 0.00054 p < 0.001
library(ggplot2)

# Create summary data frame
grant_data <- data.frame(
  Grant_Type = c("Local Government Grants", "State Government Grants", "Federal Government Grants"),
  F_Statistic = c(2.78, 3.57, 3.72),
  p_value = c(0.0072, 0.00081, 0.00054)
)

# Plot
ggplot(grant_data, aes(x = reorder(Grant_Type, F_Statistic), y = F_Statistic)) +
  geom_col(fill = "steelblue") +
  coord_flip() +
  geom_text(aes(label = paste0("F = ", F_Statistic, "\np = ", p_value)),
            hjust = -0.1, size = 3.5) +
  labs(
    title = "Rao & Scott-Adjusted Chi-Squared Test Results by Grant Type",
    x = "Grant Type",
    y = "F Statistic"
  ) +
  theme_minimal(base_size = 12) +
  ylim(0, 4.5)

# plotly 
library(dplyr)
library(tidyr)

# Grant types to loop through
grant_vars <- list(
  "Local" = c("FndRaise_LocGvtGrnt_Seek", "FndRaise_LocGvtGrnt_Rcv"),
  "State" = c("FndRaise_StateGvtGrnt_Seek", "FndRaise_StateGvtGrnt_Rcv"),
  "Federal" = c("FndRaise_FedGvtGrnt_Seek", "FndRaise_FedGvtGrnt_Rcv")
)

# Build success_by_sector_long
success_by_sector_long <- purrr::map_dfr(
  names(grant_vars),
  function(grant_type) {
    seek_var <- grant_vars[[grant_type]][1]
    rcv_var <- grant_vars[[grant_type]][2]

    data04_cleaned %>%
      filter(.data[[seek_var]] == 1) %>%
      group_by(sector_group) %>%
      summarise(
        grant_type = grant_type,
        total_sought = n(),
        total_received = sum(.data[[rcv_var]] == 1, na.rm = TRUE),
        success_rate = round(100 * total_received / total_sought, 1),
        .groups = "drop"
      )
  }
)

library(plotly)
## Warning: package 'plotly' was built under R version 4.4.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
plot_ly(
  data = success_by_sector_long,
  x = ~success_rate,
  y = ~sector_group,
  color = ~grant_type,
  type = 'bar',
  orientation = 'h',
  text = ~paste0(
    "Grant Type: ", grant_type,
    "<br>Sector: ", sector_group,
    "<br>Success Rate: ", success_rate, "%",
    "<br>Total Sought: ", total_sought,
    "<br>Total Received: ", total_received
  ),
  hoverinfo = 'text'
) %>%
  layout(
    title = "Success Rates of Receiving Government Grants by Sector and Type",
    xaxis = list(title = "Success Rate (%)", range = c(0, 100)),
    yaxis = list(title = ""),
    barmode = 'group',
    margin = list(l = 150)
  )
Grant Type: FederalSector: I. Arts, Culture, HumanitiesSuccess Rate: 57.7%Total Sought: 279Total Received: 161Grant Type: FederalSector: II. EducationSuccess Rate: 63%Total Sought: 46Total Received: 29Grant Type: FederalSector: III. Environment & AnimalsSuccess Rate: 62%Total Sought: 100Total Received: 62Grant Type: FederalSector: IV. HealthSuccess Rate: 56.7%Total Sought: 97Total Received: 55Grant Type: FederalSector: V. Human ServicesSuccess Rate: 71.3%Total Sought: 519Total Received: 370Grant Type: FederalSector: VI. InternationalSuccess Rate: 44.4%Total Sought: 27Total Received: 12Grant Type: FederalSector: VII. Public/Societal BenefitSuccess Rate: 72.2%Total Sought: 115Total Received: 83Grant Type: FederalSector: VIII. Religion RelatedSuccess Rate: 66.7%Total Sought: 3Total Received: 2Grant Type: LocalSector: I. Arts, Culture, HumanitiesSuccess Rate: 86.1%Total Sought: 490Total Received: 422Grant Type: LocalSector: II. EducationSuccess Rate: 67.9%Total Sought: 78Total Received: 53Grant Type: LocalSector: III. Environment & AnimalsSuccess Rate: 76.9%Total Sought: 143Total Received: 110Grant Type: LocalSector: IV. HealthSuccess Rate: 82.3%Total Sought: 124Total Received: 102Grant Type: LocalSector: V. Human ServicesSuccess Rate: 80.3%Total Sought: 768Total Received: 617Grant Type: LocalSector: VI. InternationalSuccess Rate: 66.7%Total Sought: 15Total Received: 10Grant Type: LocalSector: VII. Public/Societal BenefitSuccess Rate: 79.6%Total Sought: 152Total Received: 121Grant Type: LocalSector: VIII. Religion RelatedSuccess Rate: 50%Total Sought: 4Total Received: 2Grant Type: StateSector: I. Arts, Culture, HumanitiesSuccess Rate: 83.2%Total Sought: 487Total Received: 405Grant Type: StateSector: II. EducationSuccess Rate: 68.8%Total Sought: 80Total Received: 55Grant Type: StateSector: III. Environment & AnimalsSuccess Rate: 72.7%Total Sought: 128Total Received: 93Grant Type: StateSector: IV. HealthSuccess Rate: 77.7%Total Sought: 130Total Received: 101Grant Type: StateSector: V. Human ServicesSuccess Rate: 81.7%Total Sought: 673Total Received: 550Grant Type: StateSector: VI. InternationalSuccess Rate: 53.8%Total Sought: 13Total Received: 7Grant Type: StateSector: VII. Public/Societal BenefitSuccess Rate: 72.2%Total Sought: 144Total Received: 104Grant Type: StateSector: VIII. Religion RelatedSuccess Rate: 50%Total Sought: 2Total Received: 1020406080100I. Arts, Culture, HumanitiesII. EducationIII. Environment & AnimalsIV. HealthV. Human ServicesVI. InternationalVII. Public/Societal BenefitVIII. Religion Related
FederalLocalStateSuccess Rates of Receiving Government Grants by Sector and TypeSuccess Rate (%)
library(dplyr)
library(tidyr)

# Grant types to loop through
grant_vars <- list(
  "Local" = c("FndRaise_LocGvtGrnt_Seek", "FndRaise_LocGvtGrnt_Rcv"),
  "State" = c("FndRaise_StateGvtGrnt_Seek", "FndRaise_StateGvtGrnt_Rcv"),
  "Federal" = c("FndRaise_FedGvtGrnt_Seek", "FndRaise_FedGvtGrnt_Rcv")
)

# Build success_by_sector_long
success_by_sector_long <- purrr::map_dfr(
  names(grant_vars),
  function(grant_type) {
    seek_var <- grant_vars[[grant_type]][1]
    rcv_var <- grant_vars[[grant_type]][2]

    data04_cleaned %>%
      filter(.data[[seek_var]] == 1) %>%
      group_by(sector_group) %>%
      summarise(
        grant_type = grant_type,
        total_sought = n(),
        total_received = sum(.data[[rcv_var]] == 1, na.rm = TRUE),
        success_rate = round(100 * total_received / total_sought, 1),
        .groups = "drop"
      )
  }
)


library(plotly)

plot_ly(
  data = success_by_sector_long,
  x = ~success_rate,
  y = ~sector_group,
  color = ~grant_type,
  type = 'bar',
  orientation = 'h',
  text = ~paste0(
    "Grant Type: ", grant_type,
    "<br>Sector: ", sector_group,
    "<br>Success Rate: ", success_rate, "%",
    "<br>Total Sought: ", total_sought,
    "<br>Total Received: ", total_received
  ),
  hoverinfo = 'text'
) %>%
  layout(
    title = "Success Rates of Receiving Government Grants by Sector and Type",
    xaxis = list(title = "Success Rate (%)", range = c(0, 100)),
    yaxis = list(title = ""),
    barmode = 'group',
    margin = list(l = 150)
  )
Grant Type: FederalSector: I. Arts, Culture, HumanitiesSuccess Rate: 57.7%Total Sought: 279Total Received: 161Grant Type: FederalSector: II. EducationSuccess Rate: 63%Total Sought: 46Total Received: 29Grant Type: FederalSector: III. Environment & AnimalsSuccess Rate: 62%Total Sought: 100Total Received: 62Grant Type: FederalSector: IV. HealthSuccess Rate: 56.7%Total Sought: 97Total Received: 55Grant Type: FederalSector: V. Human ServicesSuccess Rate: 71.3%Total Sought: 519Total Received: 370Grant Type: FederalSector: VI. InternationalSuccess Rate: 44.4%Total Sought: 27Total Received: 12Grant Type: FederalSector: VII. Public/Societal BenefitSuccess Rate: 72.2%Total Sought: 115Total Received: 83Grant Type: FederalSector: VIII. Religion RelatedSuccess Rate: 66.7%Total Sought: 3Total Received: 2Grant Type: LocalSector: I. Arts, Culture, HumanitiesSuccess Rate: 86.1%Total Sought: 490Total Received: 422Grant Type: LocalSector: II. EducationSuccess Rate: 67.9%Total Sought: 78Total Received: 53Grant Type: LocalSector: III. Environment & AnimalsSuccess Rate: 76.9%Total Sought: 143Total Received: 110Grant Type: LocalSector: IV. HealthSuccess Rate: 82.3%Total Sought: 124Total Received: 102Grant Type: LocalSector: V. Human ServicesSuccess Rate: 80.3%Total Sought: 768Total Received: 617Grant Type: LocalSector: VI. InternationalSuccess Rate: 66.7%Total Sought: 15Total Received: 10Grant Type: LocalSector: VII. Public/Societal BenefitSuccess Rate: 79.6%Total Sought: 152Total Received: 121Grant Type: LocalSector: VIII. Religion RelatedSuccess Rate: 50%Total Sought: 4Total Received: 2Grant Type: StateSector: I. Arts, Culture, HumanitiesSuccess Rate: 83.2%Total Sought: 487Total Received: 405Grant Type: StateSector: II. EducationSuccess Rate: 68.8%Total Sought: 80Total Received: 55Grant Type: StateSector: III. Environment & AnimalsSuccess Rate: 72.7%Total Sought: 128Total Received: 93Grant Type: StateSector: IV. HealthSuccess Rate: 77.7%Total Sought: 130Total Received: 101Grant Type: StateSector: V. Human ServicesSuccess Rate: 81.7%Total Sought: 673Total Received: 550Grant Type: StateSector: VI. InternationalSuccess Rate: 53.8%Total Sought: 13Total Received: 7Grant Type: StateSector: VII. Public/Societal BenefitSuccess Rate: 72.2%Total Sought: 144Total Received: 104Grant Type: StateSector: VIII. Religion RelatedSuccess Rate: 50%Total Sought: 2Total Received: 1020406080100I. Arts, Culture, HumanitiesII. EducationIII. Environment & AnimalsIV. HealthV. Human ServicesVI. InternationalVII. Public/Societal BenefitVIII. Religion Related
FederalLocalStateSuccess Rates of Receiving Government Grants by Sector and TypeSuccess Rate (%)

weighted- not working

library(dplyr)
library(survey)
library(tidyr)
library(plotly)

# Set up list to collect results
weighted_results <- list()

# Define grant types and variables
grant_types <- list(
  "Local"   = c("FndRaise_LocGvtGrnt_Seek", "FndRaise_LocGvtGrnt_Rcv"),
  "State"   = c("FndRaise_StateGvtGrnt_Seek", "FndRaise_StateGvtGrnt_Rcv"),
  "Federal" = c("FndRaise_FedGvtGrnt_Seek", "FndRaise_FedGvtGrnt_Rcv")
)

# Loop through each grant type
for (type in names(grant_types)) {
  seek_var <- grant_types[[type]][1]
  rcv_var <- grant_types[[type]][2]

  temp_data <- data04_cleaned %>%
    filter(.data[[seek_var]] == 1) %>%
    mutate(
      received = .data[[rcv_var]],
      grant_type = type
    )

  # Survey design with weights
  design <- svydesign(ids = ~1, weights = ~year4wt, data = temp_data)

  # Get success rate per sector group
  summary <- svyby(
    ~received,
    ~sector_group,
    design,
    svymean,
    vartype = c("ci")
  ) %>%
    mutate(
      success_rate = round(received * 100, 1),
      grant_type = type,
      lower = round(ci_l * 100, 1),
      upper = round(ci_u * 100, 1)
    ) %>%
    select(sector_group, grant_type, success_rate, lower, upper)

  weighted_results[[type]] <- summary
}

# Combine all grant types
success_by_sector_long_weighted <- bind_rows(weighted_results)



plot_ly(
  data = success_by_sector_long_weighted,
  x = ~success_rate,
  y = ~sector_group,
  color = ~grant_type,
  type = 'bar',
  orientation = 'h',
  error_x = ~list(array = upper - success_rate),
  text = ~paste(
    "Sector: ", sector_group,
    "<br>Grant Type: ", grant_type,
    "<br>Success Rate: ", success_rate, "%",
    "<br>CI: [", lower, "% - ", upper, "%]"
  ),
  hoverinfo = 'text'
) %>%
  layout(
    title = "Weighted Success Rates of Receiving Government Grants by Sector and Type",
    xaxis = list(title = "Success Rate (%)", range = c(0, 100)),
    yaxis = list(title = ""),
    barmode = 'group',
    margin = list(l = 150)
  )
Sector: I. Arts, Culture, Humanities Grant Type: Federal Success Rate: 57.9 % CI: [ 52 % - 63.7 %]Sector: II. Education Grant Type: Federal Success Rate: 66.7 % CI: [ 53 % - 80.3 %]Sector: III. Environment & Animals Grant Type: Federal Success Rate: 61 % CI: [ 51.2 % - 70.7 %]Sector: IV. Health Grant Type: Federal Success Rate: 58.6 % CI: [ 48.3 % - 68.9 %]Sector: V. Human Services Grant Type: Federal Success Rate: 71.6 % CI: [ 67.6 % - 75.6 %]Sector: VI. International Grant Type: Federal Success Rate: 45.4 % CI: [ 26.4 % - 64.5 %]Sector: VII. Public/Societal Benefit Grant Type: Federal Success Rate: 74.4 % CI: [ 66.5 % - 82.4 %]Sector: VIII. Religion Related Grant Type: Federal Success Rate: 68.1 % CI: [ 16 % - 120.3 %]Sector: I. Arts, Culture, Humanities Grant Type: Local Success Rate: 86.1 % CI: [ 83 % - 89.2 %]Sector: II. Education Grant Type: Local Success Rate: 69.6 % CI: [ 59.4 % - 79.8 %]Sector: III. Environment & Animals Grant Type: Local Success Rate: 76.8 % CI: [ 69.8 % - 83.8 %]Sector: IV. Health Grant Type: Local Success Rate: 82.1 % CI: [ 75 % - 89.2 %]Sector: V. Human Services Grant Type: Local Success Rate: 80.8 % CI: [ 78 % - 83.6 %]Sector: VI. International Grant Type: Local Success Rate: 66.4 % CI: [ 42.1 % - 90.7 %]Sector: VII. Public/Societal Benefit Grant Type: Local Success Rate: 79.3 % CI: [ 72.6 % - 86 %]Sector: VIII. Religion Related Grant Type: Local Success Rate: 45.4 % CI: [ -3.6 % - 94.4 %]Sector: I. Arts, Culture, Humanities Grant Type: State Success Rate: 83.4 % CI: [ 80 % - 86.7 %]Sector: II. Education Grant Type: State Success Rate: 70.6 % CI: [ 60.6 % - 80.6 %]Sector: III. Environment & Animals Grant Type: State Success Rate: 72.3 % CI: [ 64.4 % - 80.1 %]Sector: IV. Health Grant Type: State Success Rate: 78.7 % CI: [ 71.5 % - 85.8 %]Sector: V. Human Services Grant Type: State Success Rate: 82.6 % CI: [ 79.7 % - 85.5 %]Sector: VI. International Grant Type: State Success Rate: 53.5 % CI: [ 26 % - 80.9 %]Sector: VII. Public/Societal Benefit Grant Type: State Success Rate: 73.6 % CI: [ 66.3 % - 80.8 %]Sector: VIII. Religion Related Grant Type: State Success Rate: 51.7 % CI: [ -17.6 % - 120.9 %]020406080100I. Arts, Culture, HumanitiesII. EducationIII. Environment & AnimalsIV. HealthV. Human ServicesVI. InternationalVII. Public/Societal BenefitVIII. Religion Related
FederalLocalStateWeighted Success Rates of Receiving Government Grants by Sector and TypeSuccess Rate (%)

Rural vs Urban

While urban nonprofits had a slightly higher success rate (87.8%) than rural ones (84.6%), this difference was not statistically significant, suggesting that urban or rural classification does not strongly influence whether an organization receives funding once it seeks it.

-Weighted results interp We used a weighted chi-squared test (with Rao & Scott adjustment) to examine whether urban versus rural location influenced the likelihood of receiving any government grant among nonprofits that sought one. After applying the year4wt survey weight to account for differential response rates, we found no statistically significant association between urbanicity and funding success (F(1, 2298) = 2.37, p = 0.1239).

# nonweighted 
library(dplyr)

# Filter to organizations that sought any government grant
data_seekers <- data04_cleaned %>%
  filter(
    FndRaise_LocGvtGrnt_Seek == 1 |
    FndRaise_StateGvtGrnt_Seek == 1 |
    FndRaise_FedGvtGrnt_Seek == 1
  ) %>%
  mutate(
    received_any_grant = if_else(
      FndRaise_LocGvtGrnt_Rcv == 1 |
      FndRaise_StateGvtGrnt_Rcv == 1 |
      FndRaise_FedGvtGrnt_Rcv == 1,
      1, 0
    ),
    census_urban_area = factor(census_urban_area, levels = c(0,1), labels = c("Rural", "Urban")),
    received_any_grant = factor(received_any_grant, levels = c(0,1), labels = c("No", "Yes"))
  )

# Create a contingency table
contingency_table <- table(data_seekers$census_urban_area, data_seekers$received_any_grant)

# Run the chi-squared test
chi_result <- chisq.test(contingency_table)

# Output
print(contingency_table)
##        
##           No  Yes
##   Rural   42  231
##   Urban  248 1778
print(chi_result)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  contingency_table
## X-squared = 1.8813, df = 1, p-value = 0.1702
#weighted




library(survey)
library(dplyr)

# Filter to organizations that sought any government grant
data_seekers <- data04_cleaned %>%
  filter(
    FndRaise_LocGvtGrnt_Seek == 1 |
    FndRaise_StateGvtGrnt_Seek == 1 |
    FndRaise_FedGvtGrnt_Seek == 1
  ) %>%
  mutate(
    received_any_grant = if_else(
      FndRaise_LocGvtGrnt_Rcv == 1 |
      FndRaise_StateGvtGrnt_Rcv == 1 |
      FndRaise_FedGvtGrnt_Rcv == 1,
      1, 0
    ),
    census_urban_area = factor(census_urban_area, levels = c(0, 1), labels = c("Rural", "Urban")),
    received_any_grant = factor(received_any_grant, levels = c(0, 1), labels = c("No", "Yes"))
  )

# Define weighted survey design
design <- svydesign(ids = ~1, data = data_seekers, weights = ~year4wt)

# Run weighted chi-squared test
weighted_chi <- svychisq(~census_urban_area + received_any_grant, design = design)

# Output
print(weighted_chi)
## 
##  Pearson's X^2: Rao & Scott adjustment
## 
## data:  svychisq(~census_urban_area + received_any_grant, design = design)
## F = 2.3687, ndf = 1, ddf = 2298, p-value = 0.1239

Size of nonprofit.

Association Between Organization Size and Funding Success

A weighted chi-squared test (with the Rao & Scott adjustment) was conducted to determine whether an organization’s size is associated with its likelihood of receiving funding among those that sought it. The test revealed a statistically significant association between size and funding success, F(3.41, 7843.04) = 5.03, p = 0.0010.

This suggests that nonprofits of different sizes do not have equal success rates in securing government funding. Larger organizations may have more resources, capacity, or grant-writing experience that contributes to their higher success rates, while smaller organizations may face more barriers.

library(survey)

# Subset to organizations that sought local, state, or federal grants
data_size <- data04_cleaned %>%
  filter(
    FndRaise_LocGvtGrnt_Seek == 1 |
    FndRaise_StateGvtGrnt_Seek == 1 |
    FndRaise_FedGvtGrnt_Seek == 1
  ) %>%
  mutate(
    received_any_grant = if_else(
      FndRaise_LocGvtGrnt_Rcv == 1 |
      FndRaise_StateGvtGrnt_Rcv == 1 |
      FndRaise_FedGvtGrnt_Rcv == 1,
      1, 0
    ),
    SizeStrata = factor(SizeStrata, levels = c(1, 2, 3, 4, 5),
                        labels = c("<$100K", "$100K-$499K", "$500K-$999K", "$1M-$10M", "$10M+")),
    received_any_grant = factor(received_any_grant, levels = c(0, 1), labels = c("No", "Yes"))
  )

design_size <- svydesign(ids = ~1, weights = ~year4wt, data = data_size)

svychisq(~SizeStrata + received_any_grant, design = design_size)
## 
##  Pearson's X^2: Rao & Scott adjustment
## 
## data:  svychisq(~SizeStrata + received_any_grant, design = design_size)
## F = 5.0347, ndf = 3.413, ddf = 7843.043, p-value = 0.001015
# Weighted success rates with confidence intervals
svyby(~received_any_grant, ~SizeStrata, design_size, svymean, vartype = c("ci"))
##              SizeStrata received_any_grantNo received_any_grantYes
## <$100K           <$100K           0.19603200             0.8039680
## $100K-$499K $100K-$499K           0.14100977             0.8589902
## $500K-$999K $500K-$999K           0.11068910             0.8893109
## $1M-$10M       $1M-$10M           0.09086315             0.9091368
## $10M+             $10M+           0.07384265             0.9261573
##             ci_l.received_any_grantNo ci_l.received_any_grantYes
## <$100K                     0.14823124                  0.7561672
## $100K-$499K                0.11852481                  0.8365053
## $500K-$999K                0.08026971                  0.8588915
## $1M-$10M                   0.06726983                  0.8855435
## $10M+                      0.01136920                  0.8636839
##             ci_u.received_any_grantNo ci_u.received_any_grantYes
## <$100K                      0.2438328                  0.8517688
## $100K-$499K                 0.1634947                  0.8814752
## $500K-$999K                 0.1411085                  0.9197303
## $1M-$10M                    0.1144565                  0.9327302
## $10M+                       0.1363161                  0.9886308
library(plotly)

# Compute summary
size_summary <- svyby(~received_any_grant, ~SizeStrata, design_size, svymean, vartype = "ci")

plot_ly(
  data = size_summary,
  x = ~SizeStrata,
  y = ~received_any_grantYes,
  type = "bar",
  name = "Success Rate",
  error_y = ~list(
    array = ci_u.received_any_grantYes - received_any_grantYes,
    arrayminus = received_any_grantYes - ci_l.received_any_grantYes,
    color = '#000000'
  ),
  text = ~paste0("Success Rate: ", round(received_any_grantYes * 100, 1), "%<br>",
                 "CI: [", round(ci_l.received_any_grantYes * 100, 1), "% - ", round(ci_u.received_any_grantYes * 100, 1), "%]"),
  hoverinfo = "text",
  textposition = "none"
) %>%
  layout(
    title = "Weighted Success Rates by Organizational Size",
    xaxis = list(title = "Organization Size"),
    yaxis = list(title = "Success Rate", tickformat = ".0%", range = c(0, 1.1)),
    showlegend = FALSE
  )
<$100K$100K-$499K$500K-$999K$1M-$10M$10M+0%20%40%60%80%100%
Weighted Success Rates by Organizational SizeOrganization SizeSuccess Rate

affiliation

Weighted chi-squared tests were conducted to evaluate whether certain 501(c)(4) affiliation purposes were associated with the likelihood of receiving government funding (among those who sought it). The survey-adjusted design used Rao & Scott corrections to account for sampling weights.

Affiliation_Purpose_Candidates (p = 0.004) and Affiliation_Purpose_EndorseOpposeBallot (p = 0.004) were both significantly associated with the likelihood of receiving funding. This suggests that nonprofits affiliated with organizations that endorse/oppose candidates or ballot initiatives may experience different funding outcomes, even after seeking public support.

Affiliation_Purpose_ConductBallot was also marginally significant (p = 0.0263), suggesting a possible relationship worth further exploration.

In contrast, Affiliation_Purpose_Lobby and Affiliation_Purpose_Other showed no statistically significant relationship with funding outcomes (p = 0.3191 for both).

library(dplyr)
library(survey)
library(tibble)

# Step 1: Filter to seekers of any government grant and create received_any_grant
data_seekers <- data04_cleaned %>%
  filter(
    FndRaise_LocGvtGrnt_Seek == 1 |
    FndRaise_StateGvtGrnt_Seek == 1 |
    FndRaise_FedGvtGrnt_Seek == 1
  ) %>%
  mutate(
    received_any_grant = if_else(
      FndRaise_LocGvtGrnt_Rcv == 1 |
      FndRaise_StateGvtGrnt_Rcv == 1 |
      FndRaise_FedGvtGrnt_Rcv == 1,
      1, 0
    )
  )

# Step 2: Define the variables to test
affiliation_vars <- c(
  "Affiliation_Purpose_Lobby",
  "Affiliation_Purpose_Candidates",
  "Affiliation_Purpose_ConductBallot",
  "Affiliation_Purpose_EndorseOpposeBallot",
  "Affiliation_Purpose_Other"
)

# Step 3: Loop through variables and store results
chi_results <- lapply(affiliation_vars, function(var) {
  
  # Clean dataset for each variable
  data_test <- data_seekers %>%
    filter(!is.na(.data[[var]])) %>%
    mutate(
      received_any_grant = factor(received_any_grant, levels = c(0, 1), labels = c("No", "Yes")),
      affiliation = factor(.data[[var]], levels = c(0, 1), labels = c("No", "Yes"))
    )
  
  # Survey design with weights
  design_test <- svydesign(ids = ~1, weights = ~year4wt, data = data_test)
  
  # Run chi-squared test
  result <- svychisq(~affiliation + received_any_grant, design = design_test)
  
  # Return summary row
  tibble(
    Variable = var,
    F_statistic = round(result$statistic, 4),
    df_numerator = round(result$parameter[[1]], 3),
    df_denominator = round(result$parameter[[2]], 3),
    p_value = signif(result$p.value, 4)
  )
})

# Step 4: Combine results into a single table
chi_results_df <- bind_rows(chi_results)

# View the results
print(chi_results_df)
## # A tibble: 5 × 5
##   Variable                       F_statistic df_numerator df_denominator p_value
##   <chr>                                <dbl>        <dbl>          <dbl>   <dbl>
## 1 Affiliation_Purpose_Lobby             1.05            1             19  0.319 
## 2 Affiliation_Purpose_Candidates       10.7             1             19  0.004 
## 3 Affiliation_Purpose_ConductBa…        5.80            1             19  0.0263
## 4 Affiliation_Purpose_EndorseOp…       10.7             1             19  0.004 
## 5 Affiliation_Purpose_Other             1.05            1             19  0.319